// 登陆表单账号/手机验证
var ts=document.getElementById('ts');
var name = document.getElementById('name');
var pas1 = document.getElementById('pas');

function namfn1() {
    // console.log(111)
    if( $('#name').val() == "") {
        ts.innerHTML = "*账号不能为空";
        return false;
    }else{
      var regex1 = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
      var zhanghao =  /^[a-zA-Z_]\w{3,23}$/;
       if( zhanghao.test($('#name').val())  || regex1.test($('#name').val()) == true) {
            ts.innerHTML = "";
        return true;
        } else {
            ts.innerHTML = "*账号输入不正确";
            return false;
         }
    }
    
   
}
name.onblur = namfn1;
// // 登陆表单密码验证
function psdfn1() {
    if(pas1.value == ""){
       ts.innerHTML  ="*密码不能为空";
        return false;
    }else{
      var regex2 = /^\d{6,}$/;
        if(regex2.test(pas1.value) == true){
           return true;
         } else {
            ts.innerHTML = "*密码不对";
           return false;
    }
    }
    
   
}
pas1.onblur = psdfn1;



function fn1() {
       var res1= namfn1();
       var res2= psdfn1();
       return res2 && res1;
}   
$('#btn').on('click', function(){
                var res1= namfn1();
                var res2= psdfn1();
                if(res1 && res2){
                     $.ajax({
                type: 'POST',
                url: "/home/login/login",
                data: $('form').serialize(),
                dataType: 'json',
                success: function(data){
                    if (data.status ==1) {
                        window.location.href="/";
                    }
                    if(data.status ==2) {
                       document.getElementById('ts').innerHTML = "*密码错误";
                    }
                    if(data.status==3 && res1 !=''){
                        document.getElementById('ts').innerHTML = "*该用户不存在";
                    }
                }
 });
   }else{
    return false;
    }
           
        })
   